using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NPBehave;
using Sirenix.OdinInspector;
using Sirenix.Serialization;
using UnityEngine;

namespace BTEditor
{
    [BTDecorator]
    public class BlackboardCondition : Decorator
    {       
        public override Type GetNodeType()
        {
            return typeof(NPBehave.BlackboardCondition);
        }

        public override ErrorType GetIsVaild()
        {
            if (string.IsNullOrEmpty("") || !BelongNode.IsHaveChild || BelongNode.ChildNodeList.Count > CanAddNodeCount)
            {
                return ErrorType.Error;
            }

            return ErrorType.None;
        }

        protected override void DealField(StringBuilder sb)
        {
            sb.Append($"{op.ToArgs()},");
            if (BlackboardData!=null)
            {
                switch (BlackboardData.ValueType)
                {
                    case ValueType.Int:
                        sb.Append($"{BlackboardData.Value_Int},");
                        break;
                    case ValueType.Float:
                        sb.Append($"{BlackboardData.Value_Float.ToArgs()},");
                        break;
                    case ValueType.Bool:
                        sb.Append($"{BlackboardData.Value_Bool.ToArgs()},");
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }          
            sb.Append($"{stopsOnChange.ToArgs()},");
        }

        [HideLabel]
        [OdinSerialize]
        [PropertyOrder(-999)]
        [BoxGroup("Blackboard",CenterLabel = true)]
        [ValueDropdown("ValuesFunction",IsUniqueList = true,DropdownTitle = "选择定义值", DropdownHeight = 500)]
        public BlackboardData BlackboardData;
        
        [Title("比较操作")]
        [EnumToggleButtons]
        [HideLabel]
        [OdinSerialize]
        public Operator op;

        [Title("值变化时处理")]
        [EnumToggleButtons]
        [HideLabel]
        [OdinSerialize]
        public Stops stopsOnChange;
        
        private IEnumerable<BlackboardData> ValuesFunction()
        {
            return BTEditorProperty.Instance.CurAsset.DefineBlackboard.ToArray();
        }

    }
}